package com.lujianfei.babymilkmemory.database

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.lujianfei.babymilkmemory.MyApplication
import com.lujianfei.babymilkmemory.database.table.HistoryTable
import com.lujianfei.luggage.database.dao.HistoryDao


/**
 * Author: lujianfei
 * Date: 2024/12/9 9:27
 * Description: 数据库
 */

@Database(entities = [HistoryTable::class], version = 1)
abstract class AppDatabase : RoomDatabase() {

    abstract fun historyDao(): HistoryDao

    companion object {
        @Volatile
        private var INSTANCE: AppDatabase? = null

        fun instance(): AppDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    MyApplication.INSTANCE.applicationContext,
                    AppDatabase::class.java,
                    "app_database"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}